function Queue (manifest, options) {
  this.manifest = manifest
  this.options = options || {}
  this.result = {}
  this.count = 0
  this.len = manifest.length
  this.load()
}
Queue.DEFAULT = {
  each: null,
  all: null
}
Queue.prototype.load = function () {
  var _this = this
  this.manifest.forEach((o, i) => {
    var img = new Image()
    img.addEventListener('load', function () {
      _this.tick()
    })
    img.addEventListener('error', function () {
      _this.tick()
    })
    img.src = o.url
    o.id && (this.result[o.id] = img)
  })
}
Queue.prototype.tick = function () {
  this.count++
  this.options.each && this.options.each(this.count, this.len)
  if (this.count >= this.len) {
    this.options.complete && this.options.complete()
  }
}

export default function (manifest, options) {
  return new Queue(manifest, options)
}
